<?php


use p5\objects\HtmlUtils;
use p5\objects\RequestUtils;
use p5\objects\SessionUtils;

function trim_arg($url)
{
    $urls = explode("?", $url);
    return $urls[0];
}

function format_html($html)
{
    $value = str_replace(">", ">\r\n", $html);
    return $value;
}

function get($argName, $defaultValue = "", $replaceQuota = false)
{
    return RequestUtils::get($argName, $defaultValue, $replaceQuota);
}

function get_int($argName, $defaultValue = -1)
{
    return RequestUtils::get_int($argName, $defaultValue);
}

function get_parameter($argName, $default = "")
{
    return RequestUtils::get_parameter($argName, $default);
}

function value_replace($str)
{
    $str = str_replace("<", "&lt;", $str);
    $str = str_replace(">", "&gt;", $str);
    $str = str_replace("\"", "&quot;", $str);
    return $str;
}

function html_replace($str)
{
    $str = str_replace("<", "&lt;", $str);
    $str = str_replace(">", "&gt;", $str);
    $str = str_replace("\n", "<BR>", $str);
    $str = str_replace(" ", "&nbsp;", $str);
    $str = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", $str);
    return $str;
}

function text_to_html($str)
{
    $str = str_replace(" ", "&nbsp;", $str);
    $str = str_replace("\n", "<br>", $str);
    return $str;
}


function get_parameters($names = array(), $filter_empty_value = true)
{
    return RequestUtils::get_parameters($names, $filter_empty_value);
}

function get_session_parameters($list = array(), $isPageScope = true)
{
    return SessionUtils::get_session_parameters($list, $isPageScope);
}


function get_website_url()
{
    return RequestUtils::get_website_url();
}

function get_ahead_path($path, $n)
{
    return RequestUtils::get_ahead_path($path, $n);
}


function get_remote_addr()
{
    return RequestUtils::get_remote_addr();
}

function _get_browser()
{
    return RequestUtils::_get_browser();
}


function get_client_browser()
{
    return RequestUtils::get_client_browser();
}


function is_ie()
{
    return RequestUtils::is_ie();
}

function is_firefox()
{
    return RequestUtils::is_firefox();
}

function is_chrome()
{
    return RequestUtils::is_chrome();
}

function is_ie7()
{
    return RequestUtils::is_ie7();
}

function is_ie8()
{
    return RequestUtils::is_ie8();
}

function is_ie9()
{
    return RequestUtils::is_ie9();
}


function get_brief($txt, $length, $start = 0)
{
    return HtmlUtils::get_brief($txt, $length, $start);
}

function shorten($txt, $len = 10, $addTitle = true)
{
    return HtmlUtils::shorten($txt, $len, $addTitle);
}

function write_matrix_into_table($result)
{
    echo "<table class='table_list'>";
    $index = 0;
    while (list($key, $value) = each($result)) {
        if ($index++ % 2 == 0) {
            continue;
        }
        echo "<tr>";
        echo "	<td class='col_label'>$key</td>";
        echo "	<td class='col_value'>$value</td>";
        echo "</tr>";
    }
    echo "</table>";
}

function note_form_session()
{
    $key = "_form_session_id";
    $string = get($key);
    if (!empty($string)) {
        set_page_session($key, $string);
    }
}

function check_form_session()
{
    $key = "_form_session_id";
    $string = get($key);
    if (!empty($string)) {
        if ($string == get_page_session($key)) {
            return false;
        }
    }
    return true;
}

function note_back_url($flag = "")
{
    RequestUtils::note_back_url($flag);
}

function load_back_url($flag = "")
{
    return RequestUtils::load_back_url($flag);
}

function to_ints($value)
{
    if (is_array($value)) {
        for ($i = 0; $i < count($value); $i++) {
            $value[$i] = to_int($value[$i]);
        }
        return $value;
    } else {
        return $value * 1;
    }
}